package com.huike.web.controller.report;


import com.huike.report.domain.vo.IndexTodayInfoVO;
import com.huike.report.domain.vo.IndexTodoInfoVO;
import com.huike.report.domain.vo.IndexVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.huike.common.core.domain.AjaxResult;
import com.huike.report.service.IReportService;

import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.util.Date;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/index")
public class IndexController {

    @Autowired
    private IReportService reportService;

    /**
     * 首页--基础数据统计
     *
     * @param beginCreateTime
     * @param endCreateTime
     * @return
     */
    @GetMapping("/getBaseInfo")
    public AjaxResult getBaseInfo(@RequestParam("beginCreateTime") String beginCreateTime,
                                  @RequestParam("endCreateTime") String endCreateTime) {
        return AjaxResult.success(reportService.getBaseInfo(beginCreateTime, endCreateTime));
    }

    /**
     * 查询今日简报
     *
     * @return
     */
    @GetMapping("/getTodayInfo")
    public AjaxResult getTodayInfo() {
//        LocalDate now = LocalDate.now();
        Date date = new Date();
        String now = new SimpleDateFormat("yyyy-MM-dd").format(date);
        IndexTodayInfoVO todayInfo = reportService.getTodayInfo(now);
        return AjaxResult.success(todayInfo);

    }

    /**
     * 查询待办事项
     *
     * @param beginCreateTime
     * @param endCreateTime
     * @return
     */
    @GetMapping("/getTodoInfo")
    public AjaxResult getTodoInfo(@RequestParam("beginCreateTime") String beginCreateTime,
                                  @RequestParam("endCreateTime") String endCreateTime) {
        IndexTodoInfoVO todoInfo = reportService.getTodoInfo(beginCreateTime, endCreateTime);
        return AjaxResult.success(todoInfo);
    }

    /**
     * 商机转化龙虎榜
     */
    @GetMapping("/businessChangeStatistics")
    public AjaxResult businessChangeStatistics(@RequestParam("beginCreateTime") String beginCreateTime,
                                               @RequestParam("endCreateTime") String endCreateTime,
                                               @RequestParam("deptId") Integer deptId) {
        List<Map<String, Object>> maps = reportService.businessChangeStatistics(beginCreateTime, endCreateTime, deptId);
        return AjaxResult.success(maps);
    }

    /**
     * 线索龙虎棒
     *
     * @param beginCreateTime
     * @param endCreateTime
     * @return
     */
    @GetMapping("/salesStatistic")
    public AjaxResult salesStatistic(@RequestParam("beginCreateTime") String beginCreateTime,
                                     @RequestParam("endCreateTime") String endCreateTime) {
        List<Map<String, Object>> maps = reportService.salesStatistic(beginCreateTime, endCreateTime);
        return AjaxResult.success(maps);
    }


}